package yuxi.zy1;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class demo2 {
    public static void main(String[] args) throws Exception {
        SAXReader reader = new SAXReader();
        Document read = reader.read("D:\\ideadashuju12\\liu_ya_kai\\src\\yuxi\\zy1\\city.xml");
        Element root = read.getRootElement();
        List<Element> city = root.elements("city");
        for (Element citys:city){
            List<Element> list = citys.elements();
            System.out.println("citys:"+citys.attributeValue("id"));
            System.out.println("cityname:"+citys.elementText("cityname"));
            System.out.println("cityarea:"+citys.elementText("cityarea"));
            System.out.println("population:"+citys.elementText("population"));
        }
        /*for (Element citys:city){
            List<Element> list = citys.elements();
            System.out.println("citys:"+citys.attributeValue("id"));
            for (Element element : list) {
                System.out.println(element.getName()+":"+element.getText());
            }
        }*/
    }
}
